#include "XAnimation.h"

XAnimation::XAnimation(){
	m_frames = NULL;
	m_frame_count = 0;
	m_anim_name = "UNKNOWN";
}

XAnimation::~XAnimation(){
	delete m_frames;
}

void XAnimation::InsertFrames(XFrame* data, int count){
	if (data != NULL){
		m_frames = data;
		m_frame_count = count;
	}
}

XFrame* XAnimation::GetFrames(){
	return m_frames;
}

void XAnimation::SetAnimationName(string name){
	m_anim_name = name;
}

string XAnimation::GetAnimationName(){
	return m_anim_name;
}

void XAnimation::SetTotalBones(int bones_num){
	m_bone_count = bones_num;
}
int XAnimation::GetTotalBones(){
	return m_bone_count;
}
void XAnimation::SetAnimationRate(float rate){
	m_anim_rate = rate;
}
float XAnimation::GetAnimationRate(){
	return m_anim_rate;
}

void XAnimation::UpdateSkeleton(vector<XBone*> skeleton,int frame){
	if (frame >= m_frame_count / m_bone_count)
		return;
	int start = frame*m_bone_count;
	for (int i = start; i < start + m_bone_count; i++){
		skeleton[i - start]->SetOffest(m_frames[i].m_location);
		skeleton[i - start]->SetRotation(m_frames[i].m_rotation);
	}
	for each (XBone* bone in skeleton)
	{
		bone->UpdateBone();
		bone->CalcFinalTransformMatrix();
	}
}

int XAnimation::GetFrameCount(){
	return m_frame_count/m_bone_count;
}